/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Nguyen Van Hai
 */
public class DateTime {

    public static Date addDay(int day) {
        Calendar cal = Calendar.getInstance();
        cal.add(java.util.Calendar.DATE, day);
        // cal.add(java.util.Calendar.MINUTE,1);
        return cal.getTime();
    }

    public static Date addMinute(int minute) {
        Calendar cal = Calendar.getInstance();
        cal.add(java.util.Calendar.MINUTE, minute);
        return cal.getTime();
    }

    public static String formatDate2String(Date date, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }

    public static Date formatString2Date(String date, String pattern) {
        Date result = null;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat(pattern);
            result = formatter.parse(date);
        } catch (ParseException ex) {
        }
        return result;
    }

    public static void main(String[] agrs) {
        System.out.println(formatDate2String(new Date(), "dd/MM/yyyy"));
    }
}
